package cn.zust.edu.cn;

import javax.swing.*;
import java.awt.*;

public class Circle implements IShape{


    Point ptCenter;

    int radius;

    public Circle(Point ptCenter, int radius) {
        this.ptCenter = ptCenter;
        this.radius = radius;
    }

    @Override
    public double perimeter() {
        return 2*Math.PI*radius;
    }

    @Override
    public double area() {
        return Math.PI*radius*radius;
    }

    @Override
    public void draw() {
        double perimeter = perimeter();
        double area = area();
        System.out.println("绘制圆 ——— 周长: " + perimeter + ",面积:" + area);
        JFrame frame = new JFrame("绘制圆");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(400, 400);

        JPanel panel = new JPanel() {
            @Override
            protected void paintComponent(Graphics g) {
                super.paintComponent(g);
                g.setColor(Color.RED);
                int diameter = radius * 2;
                g.drawOval(ptCenter.x - radius, ptCenter.y - radius, diameter, diameter);
            }
        };

        frame.add(panel);
        frame.setVisible(true);
    }


}
